# -*- coding:utf-8 -*-

# 导入单元测试包
import unittest

# 导入selenium
from selenium import webdriver

import sys
reload(sys)
sys.setdefaultencoding("utf-8")

# 声明类 继承单元测试
class Login(unittest.TestCase):



    # 每一条单元测试用例执行之前执行的方法
    def setUp(self):

        # 打开浏览器self 是指类本身
        self.driver = webdriver.Firefox()

        # 设置最大
        self.driver.maximize_window()

        # 打开登录页面
        self.driver.get(
            "https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F%3Fcu%3Dtrue%26utm_source%3Dbaidu-pinzhuan%26utm_medium%3Dcpc%26utm_campaign%3Dt_288551095_baidupinzhuan%26utm_term%3D0f3d30c8dba7459bb52f2eb5eba8ac7d_0_d9bd886f08364f0c8f06ba6df20c0c7f"
        )

        # 设置休眠时间
        self.driver.implicitly_wait(5)

        pass

    # 每一条单元测试执行之后执行 的方法
    def tearDown(self):

        # 关闭浏览器
        self.driver.quit()

        pass

    #测试用例是以test开头的
    def test_us_pw(self):

        u"""用户名正确，密码正确"""
        self.login_tab_r = self.driver.find_element_by_class_name("login-tab-r")

        # 点击一下
        self.login_tab_r.click()

        #查找
        loginname = self.driver.find_element_by_id("loginname").send_keys("")
        nloginpwd = self.driver.find_element_by_id("nloginpwd").send_keys("")
        loginsubmit = self.driver.find_element_by_id("loginsubmit").click()

        self.driver.implicitly_wait(2)
        msg_error = self.driver.find_element_by_class_name("msg-error")

        message = msg_error.text

        #进行断言
        self.assertEqual(message,u"请输入账户名和密码")

        pass
